<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Agent Class - Usage - Fuel Documentation</title>
	<link href="../../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../assets/js/nav.js"></script>
	<script type="text/javascript" src="../../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Agent Class</h2>

		<p>The agent class allows you to retrieve information about browser type, version, platform or operating system, etc, based on the clients User Agent string.</p>

		<section>
			<h2>Usage</h2>

			<article>
				<h4 id="method_accepts_charset">accepts_charset($charset = 'utf-8')</h4>
				<p>Check if the current browser accepts a specific character set.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$charset</kbd></th>
									<td><i>string</i></td>
									<td>Name of the characterset</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>boolean</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if the users browser accepts iso-8859-1
if (Agent::accepts_charset('iso-8859-1'))
{
	echo "Yes, the browser accepts this characterset!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_accepts_language">accepts_language($language = 'en')</h4>
				<p>Check if the current browser accepts a specific ISO language code.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$language</kbd></th>
									<td><i>string</i></td>
									<td>ISO language code</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>boolean</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if the users browser accepts Flemish (Belgian Dutch)
if (Agent::accepts_language('nl_BE'))
{
	echo "Yes, the browser is configured for the Flemish language!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_browser">browser()</h4>
				<p>Returns the normalized browser name from the user agent string.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>string</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Process based on the browser name
switch (Agent::browser())
{
	case 'Firefox':
		// do something specific here
		break;
	case 'Internet Explorer':
		// do something specific here
		break;
	case 'Chrome':
		// do something specific here
		break;
	case 'Unknown':
		// do something specific here
		break;
	default:
		// these are not all supported browser...
		break;
}</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_platform">platform()</h4>
				<p>Returns the normalized platform name from the user agent string.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>string</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Process based on the browser platform
switch (Agent::platform())
{
	case 'Win95':
	case 'Win98':
	case 'WinNT':
	case 'WinME':
	case 'Win2000':
		// do something specific here
		break;
	case 'WinXP':
	case 'WinVista':
	case 'Win7':
		// do something specific here
		break;
	case 'Linux':
		// do something specific here
		break;
	case 'MacOSX':
	case 'MacPPC':
		// do something specific here
		break;
	case 'SunOS':
	case 'FreeBSD':
	case 'Debian':
	case 'HP-UX':
	case 'IRIX64':
		// do something specific here
		break;
	case 'unknown':
		// do something specific here
		break;
	default:
		// these are not all supported platforms...
		break;
}</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_version">version()</h4>
				<p>Returns the browser version.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>float</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if an old Internet Explorer version is used
if (Agent::browser() == 'Microsoft Internet Explorer' and Agent::version() &lt; 7)
{
	echo "Sorry, no support for outdated browsers!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_charsets">charsets()</h4>
				<p>Returns an array with all charactersets accepted by the browser.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>array</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if the users browser accepts iso-8859-1
$sets = Agent::charsets();
if (in_array('iso-8859-1', $sets))
{
	echo "Yes, the browser accepts this characterset!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_languages">languages()</h4>
				<p>Returns an array with all ISO languages accepted by the browser.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>array</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if the users browser accepts Flemish (Belgian Dutch)
$lang = Agent::languages();
if (in_array('nl_BE', $lang))
{
	echo "Yes, the browser is configured for the Flemish language!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_properties">properties()</h4>
				<p>Returns an array with all properties of the detected browser.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>array</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Get the browser properties
$properties = Agent::properties();

/**
 * These are the supported properties, and their default value
 *
 * $properties = array(
 * 	'Browser'             => "unknown",
 * 	'Version'             => 0,
 * 	'MajorVer'            => 0,
 * 	'MinorVer'            => 0,
 * 	'Platform'            => 'unknown',
 * 	'Alpha'               => false,
 * 	'Beta'                => false,
 * 	'Win16'               => false,
 * 	'Win32'               => false,
 * 	'Win64'               => false,
 * 	'Frames'              => false,
 * 	'IFrames'             => false,
 * 	'Tables'              => false,
 * 	'Cookies'             => false,
 * 	'BackgroundSounds'    => false,
 * 	'JavaScript'          => false,
 * 	'VBScript'            => false,
 * 	'JavaApplets'         => false,
 * 	'ActiveXControls'     => false,
 * 	'isBanned'            => false,
 * 	'isMobile'            => false,
 * 	'isSyndicationReader' => false,
 * 	'Crawler'             => false,
 * 	'CssVersion'          => 0,
 * 	'AolVersion'          => 0,
 * );
 *
 * Note that the booleans indicate a specific supported functionality.
 * It does not indicated if it is enabled or not.
 */</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_property">property($property = null)</h4>
				<p>Return a specific browser property. See properties() for the list of supported properties.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$property</kbd></th>
									<td><i>string</i></td>
									<td>Name of the property to retrieve. The name is case-sensitive!</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>mixed</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Check if the browser supports cookies
if (Agent::property('Cookies') === true)
{
	echo "Yes, the browser supports Cookies!";
}
	</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_is_mobile">is_mobile()</h4>
				<p>Checks if the browser used is running on a mobile device.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>boolean</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Load a platform specific view
if (Agent::is_mobile())
{
	$content = View::factory('mobile\viewname');
}
else
{
	$content = View::factory('standard\viewname');
}</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="method_is_robot">is_robot()</h4>
				<p>Checks if the browser agent indicates the visitor is a robot or crawler.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>None</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>boolean</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// Load a crawler specific view (note: this is frowned upon!)
if (Agent::is_robot())
{
	$content = View::factory('robot\viewname');
}
else
{
	$content = View::factory('standard\viewname');
}</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

		</section>

	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
